<template>
  <view class="feedback-page">
    <!-- 文本返回组件 -->
    <nav-bar title="意见反馈" textAlign="center"></nav-bar>
    <!-- 反馈内容容器 -->
    <view class="feedback-content-container">
      <textarea class="feedback-textarea" v-model.trim="textContent"
        :class="{'feedback-textarea-beyond':textContent.length>150}" :maxlength="150"
        :data-maxnum="textContent.length+'/150'" placeholder="描述你要反馈的内容，最多150个字。" />
    </view>
    <!-- 提交按钮容器 -->
    <view class="submit-container">
      <view class="submit-btn" @click="submitFeedback">提交</view>
    </view>
  </view>
</template>

<script>
  import {
    postFeedbackApi
  } from "@/api/my/feedback.js"
  export default {
    data() {
      return {
        textContent: '', //所输入的内容
      };
    },
    methods: {
      // 进行反馈
      async submitFeedback() {
        if (!this.textContent) {
          uni.showToast({
            title: "请输入要反馈的内容",
            icon: "none"
          })
          return
        }
        if (this.textContent.length > 150) {
          uni.showToast({
            title: "反馈的内容需要在150字以内",
            icon: "none"
          })
          return
        }
        let reqData = {
          idea: this.textContent
        }
        const {
          data: result
        } = await postFeedbackApi(reqData)
        if (result.code === 200) {
          uni.showToast({
            title: "反馈成功，后续请留意消息界面。",
            icon: "none"
          })
          this.textContent = ""
          setTimeout(() => {
            uni.switchTab({
              url: '/pages/message/message'
            })
          }, 1000)
        } else {
          uni.showToast({
            title: "反馈失败",
            icon: "none"
          })
        }
      }
    }
  }
</script>

<style lang="scss" scoped>
  .feedback-page {
    width: 100%;
    min-height: 100vh;
    overflow: hidden;
    background: #eef2f4;

    // 反馈内容容器
    .feedback-content-container {
      width: 100%;
      background: #ffffff;
      height: 600rpx;
      padding: 32rpx;
      box-sizing: border-box;
      font-size: 32rpx;

      &:after {
        content: attr(data-maxnum);
        position: absolute;
        right: 32rpx;
        bottom: 16rpx;
        font-size: 28rpx;
        color: gray;
      }
      .feedback-textarea{
        width: 100%;
        height: 100%;
      }
    }

    // 文字超出后显示样式
    .feedback-textarea-beyond {
      &:after {
        color: #f75454;
      }
    }


    // 提交按钮容器
    .submit-container {
      padding: 32rpx;
      padding-top: 120rpx;
      box-sizing: border-box;

      // 提交按钮
      .submit-btn {
        width: 100%;
        height: 80rpx;
        background: #3FD3D1;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 28rpx;
        color: white;
        border-radius: 8rpx;
      }
    }

  }
</style>
